using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPCoco.Tasks
{
    public class DelegateTask : Task 
    {
        public DelegateTask(Delegate method, params object[] parameters)
            : base()
        {
            this.method = method; this.parameters = parameters;
        }

        public DelegateTask(Delegate method)
            : this(method, null)
        {

        }

        public override void Initialize()
        {
            base.Initialize();
            hasEnded = false;
        }

        Delegate method;
        object[] parameters;

        bool hasEnded = false;

        public override void Update(float time)
        {
            hasEnded = true;
            method.DynamicInvoke(parameters);
        }

        public override bool HasEnded()
        {
            return hasEnded;
        }

        public override void Finish()
        {
            
        }

        public override Task Clone()
        {
            return new DelegateTask(method, parameters);
        }

        public override Task Reverse()
        {
            return Clone();
        }
    }
}
